package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CleaningOrder;
import com.ruoyi.system.service.ICleaningOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 清洁服务订单Controller
 * 
 * @author ruoyi
 * @date 2021-06-16
 */
@RestController
@RequestMapping("/system/cleaning")
public class CleaningOrderController extends BaseController
{
    @Autowired
    private ICleaningOrderService cleaningOrderService;

    /**
     * 查询清洁服务订单列表
     */
//    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(CleaningOrder cleaningOrder)
    {
        startPage();
        List<CleaningOrder> list = cleaningOrderService.selectCleaningOrderList(cleaningOrder);
        return getDataTable(list);
    }

    /**
     * 导出清洁服务订单列表
     */
//    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "清洁服务订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CleaningOrder cleaningOrder)
    {
        List<CleaningOrder> list = cleaningOrderService.selectCleaningOrderList(cleaningOrder);
        ExcelUtil<CleaningOrder> util = new ExcelUtil<CleaningOrder>(CleaningOrder.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 获取清洁服务订单详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{coId}")
    public AjaxResult getInfo(@PathVariable("coId") Long coId)
    {
        return AjaxResult.success(cleaningOrderService.selectCleaningOrderById(coId));
    }

    /**
     * 新增清洁服务订单
     */
//    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "清洁服务订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CleaningOrder cleaningOrder)
    {   cleaningOrder.setCoCreattime(new Date());
        return toAjax(cleaningOrderService.insertCleaningOrder(cleaningOrder));
    }


    /**
     * 修改清洁服务订单
     */
//    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "清洁服务订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CleaningOrder cleaningOrder)
    {
        return toAjax(cleaningOrderService.updateCleaningOrder(cleaningOrder));
    }

    /**
     * 删除清洁服务订单
     */
//    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "清洁服务订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{coIds}")
    public AjaxResult remove(@PathVariable Long[] coIds)
    {
        return toAjax(cleaningOrderService.deleteCleaningOrderByIds(coIds));
    }
}
